package com.example.timeue;

import java.util.Calendar;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TimePicker;

public class MainActivity extends Activity {
	private EditText et_time;
	private Button bt_set;
	private int mHour;
	private int mMinute;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		et_time=(EditText) findViewById(R.id.editText1);
		bt_set=(Button) findViewById(R.id.button1);
		bt_set.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				handler.sendEmptyMessage(1);
			}
		});
		
		
		
		
		
	}
	Handler handler=new Handler(){
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			switch (msg.what) {
			case 1:
			{
//				 Calendar c = Calendar.getInstance(); 
//			       mHour = c.get(Calendar.HOUR_OF_DAY);
//			       mMinute = c.get(Calendar.MINUTE);
//			       et_time.setText(mHour+":"+mMinute+"");
				String time=et_time.getText().toString();
				mHour=Integer.parseInt(time.subSequence(0, 2).toString());
				mMinute=Integer.parseInt(time.substring(3, 5).toString());
				new TimePickerDialog(MainActivity.this,android.R.style.Widget_Holo_Light, onTimeSetListener, mHour, mMinute, true)
				.show();
			}
				break;
			case 2:
			{
				et_time.setText(new StringBuilder().append((mHour < 10) ? "0" + mHour : mHour).append(":").append((mMinute < 10) ? "0" + mMinute : mMinute));
			}

			default:
				break;
			}
		}
	};
	private TimePickerDialog.OnTimeSetListener onTimeSetListener=new OnTimeSetListener() {
		
		@Override
		public void onTimeSet(TimePicker timePicker, int hour, int minute) {
			// TODO Auto-generated method stub
			mHour=hour;
			mMinute=minute;
			handler.sendEmptyMessage(2);
		}
	};
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	

}
